<?php

class LoginWorker extends Worker{
	/**
	 * loginName：
	 * password:
	 */
	public function login(){
		$runData = $this->getRunData();
		if(isset($runData['loginName'],$runData['password'])){
			$userModel = $this->loadModel("User");
			$sql = "select * from {$userModel->getTable()} where loginName = '{$runData['loginName']}'";			
			$userInfo  = $userModel->getRow($sql);
			if($userInfo){
				if($userInfo['password'] == md5Password($runData['password'],$userInfo['salt'])){
                                        if( 0 == $userInfo['state']){
                                            $usql = " SELECT * FROM pk_user_info WHERE userID = '{$userInfo['id']}' LIMIT 1 ";
                                            $userBase = $userModel->getRow($usql);
                                            $userArr['userID'] = $userBase['userID'];
                                            $userArr['userName'] = $userBase['userName'];
                                            $userArr['exp'] = $userBase['exp'];
                                            $userArr['grade'] = $userBase['grade'];
                                            $userArr['payNO'] = $userBase['payNO'];
                                            $userArr['maxPayNO'] = $userBase['maxPayNO'];
                                            $userArr['jetton'] = $userBase['jetton'];
                                            $userArr['money'] = $userBase['money'];
                                            $userArr['avatar'] = $userBase['avatar'];
                                            $userArr['postion'] = $userBase['postion'];
                                            $userArr['signature'] = $userBase['signature'];
                                            $userArr['victory'] = $userBase['victory'];
                                            $this->socketWrite(array('code'=>1,'data'=>$userArr));return;
                                        }else{
                                            //用户被禁用
                                            $this->socketWrite(array('code'=>0,'data'=>'is stop'));return;    
                                        }
				}else{
					$this->socketWrite(array('code'=>0,'data'=>'password error'));return;
				}
			}
			$this->socketWrite(array('code'=>0,'data'=>'no have user'));return;
		}else{
			$this->socketWrite(array('code'=>0,'data'=>'please enter all'));return;
		}
	}
        
        
}